package com.example.demo;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;

public class MyBatisPusCodeGenerator {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/test", "root", "root")  // 数据库连接
                .globalConfig(builder -> builder  // 公共配置
                        .author("CDHong")  // CDHong
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                        .commentDate("yyyy-MM-dd HH:mm")
                )
                .packageConfig(builder -> builder  // 包管理，指定名字和是否生成
                        .parent("com.example.demo")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                        .controller("controller")
                )
                .strategyConfig(builder -> builder   // 指定生成规则
                        .addInclude("emp","dept") // 要生成的表名
                        .entityBuilder()
                        .enableLombok()
                        .controllerBuilder()  // 生成Controller
                        .enableRestStyle() // 添加RestController注解
                        .enableHyphenStyle() // 如果表名是驼峰，则转为中划线连接
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }

}
